Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 Search this book:
Previous | Table of Contents | Next
Then, at runtime: 4. In the Form_Load event, specify the tab and Frame that will be displayed initially. Also, use the Move method to position each Frame to completely cover the tab’s client area. 5. In the TabStrip’s Clicked event procedure, read the SelectedItem.Index property to determine which tab was clicked. If it is the same as the currently displayed tab, do nothing and exit the Sub. 6. If a different tab was clicked, set the Visible property of the currently displayed Frame to False and the Visible property of the Frame corresponding to the just-clicked tab to True. 7. Set the global variable to reflect the newly displayed tab. Here is some example code both to set up the TabStrip when the form loads and to respond to clicks. Assume that the TabStrip is named TabStrip1, the array of Frame controls is called Frame1, and the global variable for keeping track of the current Tab is called CurrentTab:
    Private Sub Form_Load()

        Dim i As Integer

        ‘ Move all frames to fill client area. Set
        ‘ Visible to False and BorderStyle to
        ‘ None for all.
        For i = 0 To Frame1.Count - 1
        With Frame1(i)
            .Move TabStrip1.ClientLeft, _
               TabStrip1.ClientTop, _
               TabStrip1.ClientWidth, _
               TabStrip1.ClientHeight
            .Visible = False
            .BorderStyle = 0
        End With
        Next i

        ‘ Make Tab 1 active and its Frame visible.
        CurrentTab = 1
        Set TabStrip1.SelectedItem = TabStrip1.Tabs(CurrentTab)
        Frame1(CurrentTab - 1).Visible = True

    End Sub

    Private Sub TabStrip1_Click()

        If TabStrip1.SelectedItem.Index = CurrentTab _
             Then Exit Sub

        Frame1(TabStrip1.SelectedItem.Index - 1).Visible _
             = True
        Frame1(CurrentTab - 1).Visible = False
        CurrentTab = TabStrip1.SelectedItem.Index

    End Sub
At runtime, you should have the Frame controls display without a border or caption. This can be done by setting the BorderStyle property to None. At design time, however, seeing the Frame and its caption is useful, so you might want to consider leaving the BorderStyle property at Fixed Single during program design and then setting it to None in code at runtime, as was done in the previous sample code. During design, how do you work with a stack of Frame controls that are by necessity overlapping each other? The trick is to use the Order command on the Format menu. Use Bring to Front to put a Frame on “top” of the stack, so you can add controls to it and arrange them. Use Send to Back to move the current Frame to the “bottom” of the stack, so you can work on another Frame. #### ListView Control The ListView control permits you to display lists of items. I’ll bet you are already familiar with this control. Just look at Windows Explorer; the right panel in the Explorer window is a ListView control (this is, after all, why they are called Windows Common Controls—they are used in many different Windows applications). Four types of views are available in a ListView control: • Icon—Descriptive text with a large icon • SmallIcon—Descriptive text with a small icon • List—A sorted list of items • Report—Similar to List view, but permits display of subitems You can get a feel for what these views are like by opening Windows Explorer and using the commands on its View menu to try out the different views. When a ListView control is in Icon view, you can use the mouse to drag items around, rearranging them within the control as desired. Drag-and-drop is also operative, if it is enabled. SmallIcon view offers similar rearranging capabilities, but the items are displayed in list format with small icons rather than as large icons. List view appears similar to SmallIcon view, except that you cannot rearrange items, and the list is, by default, sorted. Report view offers the option of two or more columns in the list, permitting you to display additional details about each item. For example, in Windows Explorer, Report view (called Details) displays not only the file name but also its size, creation date, and so on. As is the case with the other controls we have been discussing, the ListView control uses collections. Each item displayed in the control is a ListItem object; all of these objects are within the control’s ListItems collection. This control uses one other collection, as we will soon see. Each ListView control can have two ImageList controls associated with it. The ImageList controls are used to store the icons that will be used in Icon and SmallIcon views. You can specify the ImageList controls at design time using the ListView control’s property pages, or you can set them at runtime:
    ListView1.Icons = ImageList1
    ListView1.SmallIcons = ImageList2
Adding items to the ListView control is done with (of course) the ListItems collection’s Add method. Here’s the syntax:
    ListView1.ListItems.Add index, key, text, icon, smallIcon
index and key are the same as for all the other collections we have seen—the numerical position of the new item in the collection and a unique identifying string. Text is the data to be displayed. The final two arguments—icon and smallIcon—identify the icons to be displayed with the item in Icon and SmallIcon views, respectively. These images are taken from the ImageList control or controls that were associated with the ListView control, as described earlier. You can specify an image using either its Index property or its Key property in the ImageList control. Here is how you would add a new item to a ListView control, at the next available Index position, specifying an icon by Index and a smallIcon by Key:
    ListView1.ListItems.Add , “apricot”, “Apricot”, 2, “fruit”
Previous | Table of Contents | Next